package com.yanqu.road.server.logic.activity.condition.musicroom;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;
import com.yanqu.road.utils.property.Property;

import java.math.BigInteger;
import java.util.List;

public class MusicRoomFurnitureLevelCondition extends BaseCondition {

    public MusicRoomFurnitureLevelCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.MusicRoomFurnitureLevel.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.MusicRoomFurnitureLevel.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        BigInteger param4 = taskConditionInfo.getParamList().get(3);
        return getValue().compareTo(param4) >= 0;
    }

    @Override
    protected void changeValue(Object object) {
//        List<Integer> params = (List<Integer>) object;
//        int buildId = params.get(0);
//        int furnitureKindId = params.get(1);
//        int level = params.get(2);
//        int compareBuildId = taskConditionInfo.getParamList().get(1).intValue();
//        int compareFurnitureKindId = taskConditionInfo.getParamList().get(2).intValue();
//
//        if (compareBuildId == buildId && compareFurnitureKindId == furnitureKindId) {
//            setValue(BigInteger.valueOf(level));
//        }
        initValue();
    }

    @Override
    public void initValue() {
        int compareBuildId = taskConditionInfo.getParamList().get(1).intValue();
        int compareFurnitureKindId = taskConditionInfo.getParamList().get(2).intValue();
        int furnitureLevel = player.getModule(MusicRoomModule.class).getFurnitureLevel(compareBuildId, compareFurnitureKindId);
        setValue(BigInteger.valueOf(furnitureLevel));
    }
}
